<?php
class CasosController extends AppController {

	var $name = 'Casos';
	var $helpers = array('Html', 'Form', 'Javascript','Flash');

	//==========================================//
	function index() 
	{
		$this->Caso->recursive = 0;
		$conditions=array('Caso.activo'=>1);
		$this->set('casos', $this->paginate('Caso',$conditions));
	}
	
	//==========================================//
	function view($id = null) 
	{
		if (!$id) 
		{
			$this->Session->setFlash(__('Invalido Caso.', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->set('caso', $this->Caso->read(null, $id));
	}
	//==========================================//
	function add()
	 {
		if (!empty($this->data))
		 {
			$this->Caso->create();
			$this->data['Caso']['activo']=0;
			if ($this->Caso->save($this->data)) 
			{
				$this->Session->setFlash(__('El/la Caso fue guardado', true));
				$this->redirect(array('action'=>'index'));
			} else {
				$this->Session->setFlash(__('El/la Caso No se pudo guardar.', true));
			}
		}
	}


	//====================Seccion administrativa======================//
	function admin_index() 
	{
		if(isset($this->params['admin']) && $this->params['admin']) 
		{
		// check that a user is logged in
		    $this->check_user();
	    }
		$this->layout = "admin";
		$this->Caso->recursive = 0;
		$this->set('casos', $this->paginate());
	}

	//==========================================//
	function admin_view($id = null) 
	{
		if(isset($this->params['admin']) && $this->params['admin']) 
		{
		// check that a user is logged in
		    $this->check_user();
	    }
		$this->layout = "admin";
		if (!$id) 
		{
			$this->Session->setFlash(__('Invalido Caso.', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->set('caso', $this->Caso->read(null, $id));
	}

	//==========================================//
	function admin_add() 
	{
		if(isset($this->params['admin']) && $this->params['admin'])
		{
		// check that a user is logged in
		    $this->check_user();
	    }
		$this->layout = "admin";
		if (!empty($this->data)) 
		{
			$this->Caso->create();
			if ($this->Caso->save($this->data)) 
			{
				$this->Session->setFlash(__('El/la Caso fue guardado', true));
				$this->redirect(array('action'=>'index'));
			} else {
				$this->Session->setFlash(__('El/la Caso No se pudo guardar.', true));
			}
		}
	}
	//==========================================//
	function admin_edit($id = null) 
	{
		if(isset($this->params['admin']) && $this->params['admin']) 
		{
		// check that a user is logged in
		    $this->check_user();
	    }
		$this->layout = "admin";
		if (!$id && empty($this->data)) 
		{
			$this->Session->setFlash(__('Invalid Caso', true));
			$this->redirect(array('action'=>'index'));
		}
		if (!empty($this->data)) 
		{
			if ($this->Caso->save($this->data)) 
			{
				$this->Session->setFlash(__('El/la Caso fue Guardado', true));
				$this->redirect(array('action'=>'index'));
			} 
			else 
			{
				$this->Session->setFlash(__('El/la Caso could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) 
		{
			$this->data = $this->Caso->read(null, $id);
		}
	}
	//==========================================//
	function admin_delete($id = null) 
	{	
		if(isset($this->params['admin']) && $this->params['admin']) 
		{
		// check that a user is logged in
		    $this->check_user();
	    }
		

		if (!$id) 
		{
			$this->Session->setFlash(__('Invalid id for Caso', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Caso->del($id)) {
			$this->Session->setFlash(__('Caso Eliminado', true));
			$this->redirect(array('action'=>'index'));
		}
	}

}
?>